﻿using UnityEngine;
using System;
using System.Collections;
using System.Runtime.InteropServices;

public class NativeAgent : MonoBehaviour
{
#if UNITY_EDITOR
    static string UnityNativeMethod(string args)
    {
        return "{\"result\":0, \"code\":0}";
    }

    static string UnityGetLanguages()
    {
        return "";
    }

    static void UnityLogEvent(string name, string msg)
    {

    }

#elif UNITY_IOS
	[DllImport("__Internal")]
	private static extern string UnityNativeMethod(string args);

	[DllImport("__Internal")]
	private static extern string UnityGetLanguages();

	[DllImport("__Internal")]
	private static extern void UnityLogEvent(string name, string msg);
#elif UNITY_ANDROID
	static string UnityNativeMethod(string args)
	{
		return AndroidHelper.MainActivity.Call<string> ("UnityNativeMethod", args);
	}

	static string UnityGetLanguages()
	{
		return "";
	}

	static void UnityLogEvent(string name, string msg)
	{
		AndroidHelper.MainActivity.Call ("UnityLogEvent", new object[] { name, msg });
	}
#else
    static string UnityNativeMethod(string args)
	{
		return "{\"result\":0, \"code\":0}";
	}

	static string UnityGetLanguages()
	{
		return "";
	}

	static void UnityLogEvent(string name, string msg)
	{
		
	}
#endif

    // 调用本地接口
    public string CallNative(string args)
    {
        return UnityNativeMethod(args);
    }

    // 本地回调
    public void NativeCallback(string args)
    {
        NativeManager.Instance.NativeCallback(args);
    }

    public static string GetLanguages()
    {
        return UnityGetLanguages();
    }

    public static void LogEvent(string name, string msg)
    {
        UnityLogEvent(name, msg);
    }
}
